package com.xj.dao;

import com.xj.model.Ticket;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


@Mapper
public interface TicketDAO {

  String table_name = " ticket ";
  String insert_field = " user_id, ticket, expired_at ";
  String select_field = " id, " + insert_field;

  /**
   * 插入票据
   * @param ticket
   * @return
   */
  @Insert({"insert into", table_name, "(", insert_field, ") values (#{userId},#{ticket},#{expiredAt})"})
  int addTicket(Ticket ticket);

  /**
   * 根据用户id查询票据详情
   * @param uid
   * @return
   */
  @Select({"select", select_field, "from", table_name, "where user_id=#{uid}"})
  Ticket selectByUserId(int uid);

  /**
   * 根据票据字符串查询票据详情
   * @param t
   * @return
   */
  @Select({"select", select_field, "from", table_name, "where ticket=#{t}"})
  Ticket selectByTicket(String t);

  /**
   * 根据票据id删除票据
   * @param tid
   */
  @Delete({"delete from", table_name, " where id=#{tid}"})
  void deleteTicketById(int tid);

  /**
   * 根据票据字符串删除票据
   * @param t
   */
  @Delete({"delete from", table_name, " where ticket=#{t}"})
  void deleteTicket(String t);

}
